package javapoker.view;
import javapoker.Card;
import javapoker.Hand;
import javapoker.Player;

import javax.swing.JPanel;

import java.awt.GridBagLayout;

import javax.swing.JButton;

import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.JToggleButton;

import java.awt.BorderLayout;
import java.awt.Component;

import javax.swing.Box;
import javax.swing.SpringLayout;

import java.awt.FlowLayout;

import javax.swing.BoxLayout;
import javax.swing.JLabel;

import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.RowSpec;

import javax.swing.border.BevelBorder;

import java.awt.GridLayout;
import java.util.Vector;


public class PlayerView extends JPanel {

	public static final String strHOLD = "HOLD";
	public static final String strPASS = "PASS";
	
	int numCards = 5;
	Player _player = null;
	/**
	 * Create the panel.
	 */
	
	private JLabel lblCredits = null;
	private JLabel lblTitle = null;
	private JPanel pnlCards;
	private Vector<CardView> _cardviews = null;
	
	public PlayerView(Player p) 
	{
		setLayout(new BorderLayout(0, 0));
		
		lblCredits = new JLabel("Player Credits");
		add(lblCredits, BorderLayout.SOUTH);
		
		lblTitle = new JLabel("Player Name");
		add(lblTitle, BorderLayout.NORTH);
		
		pnlCards = new JPanel();
		pnlCards.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		add(pnlCards, BorderLayout.CENTER);
		pnlCards.setLayout(new GridLayout(1, 0, 0, 0));
	
		_player = p;
		init();
	}

	public void init()
	{
		lblTitle.setText(_player.getPlayerName());
		
		display(_player.getHand());
	}
	
	public void display(Hand h)
	{
		Card temp = new Card("XX");
		h.sort();
		
		pnlCards.removeAll();
		for (int i=0; i < h.size(); i++)
		{
			temp = h.get(i);
			pnlCards.add(new CardView(temp));
		}
		
		lblCredits.setText("Cr: " + _player.getCredits());

	}
}
